package feedbackServlet;

import java.io.IOException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sessions.helpSession.HelpRequestsessionRemote;
import entities.HelpRequest;

public class ShowSingleHelpServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		drawPage(request, response);
	}

	public void drawPage(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		int idReq = Integer.parseInt(request.getParameter("idReq"));
		Context jndiCtx;
		HelpRequest help;
		try {
			jndiCtx = new InitialContext();
			HelpRequestsessionRemote hrs = (HelpRequestsessionRemote) jndiCtx
					.lookup("Progetto/HelpRequestsession/remote");
			help = hrs.getHelpRequest(idReq);
			request.getSession().setAttribute("help", help);
		} catch (NamingException e) {
			request.getSession().setAttribute("done", "error");
		}
		response.sendRedirect("/ProgettoWeb/RegisteredUser/ShowSingleHelp.jsp");
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		drawPage(request, response);
	}
}